package com.lingchou.cloud.process.client.config;


import com.lingchou.cloud.process.client.listener.global.GlobalProcessCompleteListener;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * 流程全局监听的配置
 * @author LingChou
 */
@Configuration
public class FlowAbleGlobListenerConfig implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private SpringProcessEngineConfiguration configuration;
    @Autowired
    private GlobalProcessCompleteListener globalProcessCompleteListener;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        FlowableEventDispatcher dispatcher = configuration.getEventDispatcher();
        //PROCESS_COMPLETED 超时、驳回和完成都走 撤销不走
        //任务创建全局流程结束监听 与任务创建 监听
        dispatcher.addEventListener(globalProcessCompleteListener, FlowableEngineEventType.PROCESS_COMPLETED,
                FlowableEngineEventType.TASK_CREATED);
    }
}
